﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="insertEmergency.aspx.cs" Inherits="Staff_insertEmergency" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>查詢編輯學生資料</title>
    <style type="text/css">

        .style1
        {
            font-family: 微軟正黑體;
            font-size: xx-large;
            text-align: center;
        }
        .style2
        {
            text-align: center;
        }
        .style3
        {
            width: 79%;
            border-style: solid;
            border-width: 1px;
            padding: 1px 4px;
        }
        .style4
        {}
        .style5
        {
            width: 100%;
        }
        .style7
        {
            border-style: solid;
            border-width: 1px;
            padding: 1px 4px;
        }
        .style8
        {
            width: 703px;
        }
        .style9
        {
            width: 703px;
            color: #00FF00;
            background-color: #000000;
        }
        .style10
        {
            width: 703px;
            color: #FFFF00;
            background-color: #000000;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style2">
    
        <span class="style1">查詢編輯學生資料</span><br />
        <br />
        <table align="center" class="style3">
            <tr>
                <td class="style4" colspan="2">
                    請輸入學生證號：<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="sid"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="查詢" 
                        ValidationGroup="sid" />
&nbsp;<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 
                        ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator" 
                        ValidationExpression="^[0-9]{1,20}$" style="color: #FF0000" 
                        ValidationGroup="sid">僅限證號</asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td class="style4">
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                        DeleteCommand="DELETE FROM [Student] WHERE [StudentId] = @StudentId" 
                        InsertCommand="INSERT INTO [Student] ([StudentId], [StudentName], [Birth], [Email], [Gender], [SelfIntro], [Address], [SSN], [DepartmentId]) VALUES (@StudentId, @StudentName, @Birth, @Email, @Gender, @SelfIntro, @Address, @SSN, @DepartmentId)" 
                        SelectCommand="SELECT * FROM [Student] WHERE ([StudentId] = @StudentId)" 
                        UpdateCommand="UPDATE [Student] SET [StudentName] = @StudentName, [Birth] = @Birth, [Email] = @Email, [Gender] = @Gender, [SelfIntro] = @SelfIntro, [Address] = @Address, [SSN] = @SSN WHERE [StudentId] = @StudentId">
                        <DeleteParameters>
                            <asp:Parameter Name="StudentId" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="StudentId" Type="Int32" />
                            <asp:Parameter Name="StudentName" Type="String" />
                            <asp:Parameter DbType="Date" Name="Birth" />
                            <asp:Parameter Name="Email" Type="String" />
                            <asp:Parameter Name="Gender" Type="String" />
                            <asp:Parameter Name="SelfIntro" Type="String" />
                            <asp:Parameter Name="Address" Type="String" />
                            <asp:Parameter Name="SSN" Type="String" />
                            <asp:Parameter Name="DepartmentId" Type="Int32" />
                        </InsertParameters>
                        <SelectParameters>
                            <asp:ControlParameter ControlID="TextBox1" Name="StudentId" PropertyName="Text" 
                                Type="Int32" />
                        </SelectParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="StudentName" Type="String" />
                            <asp:Parameter DbType="Date" Name="Birth" />
                            <asp:Parameter Name="Email" Type="String" />
                            <asp:Parameter Name="Gender" Type="String" />
                            <asp:Parameter Name="SelfIntro" Type="String" />
                            <asp:Parameter Name="Address" Type="String" />
                            <asp:Parameter Name="SSN" Type="String" />
                            <asp:Parameter Name="DepartmentId" Type="Int32" />
                            <asp:Parameter Name="StudentId" Type="Int32" />
                        </UpdateParameters>
                    </asp:SqlDataSource>
                </td>
                <td class="style4">
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style9">
                    學生基本資料</td>
                <td class="style10">
                    學生緊急聯絡人姓名</td>
            </tr>
            <tr>
                <td class="style8" rowspan="5">
                    <asp:FormView ID="FormView1" runat="server" DataKeyNames="StudentId" 
                        DataSourceID="SqlDataSource1">
                        <EditItemTemplate>
                            <table class="style5">
                                <tr>
                                    <td class="style7">
                                        學生證號：</td>
                                    <td class="style7">
                                        <asp:Label ID="StudentIdLabel1" runat="server" 
                                            Text='<%# Eval("StudentId") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        姓名：</td>
                                    <td class="style7">
                                        <asp:TextBox ID="StudentNameTextBox" runat="server" 
                                            Text='<%# Bind("StudentName") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        出生日期：</td>
                                    <td class="style7">
                                        <asp:TextBox ID="BirthTextBox" runat="server" 
                                            Text='<%# Bind("Birth", "{0:d}") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        性別：</td>
                                    <td class="style7">
                                        <asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        身分證號：</td>
                                    <td class="style7">
                                        <asp:TextBox ID="SSNTextBox" runat="server" Text='<%# Bind("SSN") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        電子信箱：</td>
                                    <td class="style7">
                                        <asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        地址：</td>
                                    <td class="style7">
                                        <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;</td>
                                    <td>
                                        &nbsp;</td>
                                </tr>
                            </table>
                            <br />
                            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                                CommandName="Update" Text="更新" />
                            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                                CausesValidation="False" CommandName="Cancel" Text="取消" />
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            StudentId:
                            <asp:TextBox ID="StudentIdTextBox" runat="server" 
                                Text='<%# Bind("StudentId") %>' />
                            <br />
                            StudentName:
                            <asp:TextBox ID="StudentNameTextBox" runat="server" 
                                Text='<%# Bind("StudentName") %>' />
                            <br />
                            Birth:
                            <asp:TextBox ID="BirthTextBox" runat="server" Text='<%# Bind("Birth") %>' />
                            <br />
                            Email:
                            <asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
                            <br />
                            Gender:
                            <asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>' />
                            <br />
                            SelfIntro:
                            <asp:TextBox ID="SelfIntroTextBox" runat="server" 
                                Text='<%# Bind("SelfIntro") %>' />
                            <br />
                            Address:
                            <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
                            <br />
                            SSN:
                            <asp:TextBox ID="SSNTextBox" runat="server" Text='<%# Bind("SSN") %>' />
                            <br />
                            DepartmentId:
                            <asp:TextBox ID="DepartmentIdTextBox" runat="server" 
                                Text='<%# Bind("DepartmentId") %>' />
                            <br />
                            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                                CommandName="Insert" Text="插入" />
                            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                                CausesValidation="False" CommandName="Cancel" Text="取消" />
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <table class="style5">
                                <tr>
                                    <td class="style7">
                                        學生證號：</td>
                                    <td class="style7">
                                        <asp:Label ID="StudentIdLabel" runat="server" Text='<%# Eval("StudentId") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        姓名：</td>
                                    <td class="style7">
                                        <asp:Label ID="StudentNameLabel" runat="server" 
                                            Text='<%# Bind("StudentName") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        出生日期：</td>
                                    <td class="style7">
                                        <asp:Label ID="BirthLabel" runat="server" Text='<%# Bind("Birth") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        性別：</td>
                                    <td class="style7">
                                        <asp:Label ID="GenderLabel" runat="server" Text='<%# Bind("Gender") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        身分證號：</td>
                                    <td class="style7">
                                        <asp:Label ID="SSNLabel" runat="server" Text='<%# Bind("SSN") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        電子信箱：</td>
                                    <td class="style7">
                                        <asp:Label ID="EmailLabel" runat="server" Text='<%# Bind("Email") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        地址：</td>
                                    <td class="style7">
                                        <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        &nbsp;</td>
                                    <td class="style7">
                                        &nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="style7">
                                        自我介紹：</td>
                                    <td class="style7">
                                        <asp:TextBox ID="TextBox1" runat="server" Height="179px" ReadOnly="True" 
                                            Text='<%# Bind("SelfIntro", "{0}") %>' TextMode="MultiLine" Width="294px"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;</td>
                                    <td>
                                        &nbsp;</td>
                                </tr>
                            </table>
                            <br />
                            <br />
                            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                                CommandName="Edit" Text="編輯" />
                        </ItemTemplate>
                    </asp:FormView>
                </td>
                <td class="style8">
                    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                        BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
                        CellPadding="3" DataKeyNames="StudentId" DataSourceID="SqlDataSource2" 
                        GridLines="Horizontal" Height="50px" Width="210px">
                        <AlternatingRowStyle BackColor="#F7F7F7" />
                        <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                        <Fields>
                            <asp:BoundField DataField="StudentId" HeaderText="學生證號" ReadOnly="True" 
                                SortExpression="StudentId" />
                            <asp:BoundField DataField="Name" HeaderText="緊急聯絡人姓名" SortExpression="Name" />
                            <asp:BoundField DataField="Relation" HeaderText="關係" 
                                SortExpression="Relation" />
                            <asp:CommandField ShowEditButton="True" />
                        </Fields>
                        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                    </asp:DetailsView>
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                        DeleteCommand="DELETE FROM [EmergencyContact] WHERE [StudentId] = @StudentId" 
                        InsertCommand="INSERT INTO [EmergencyContact] ([StudentId], [Name], [Relation]) VALUES (@StudentId, @Name, @Relation)" 
                        SelectCommand="SELECT * FROM [EmergencyContact] WHERE ([StudentId] = @StudentId)" 
                        UpdateCommand="UPDATE [EmergencyContact] SET [Name] = @Name, [Relation] = @Relation WHERE [StudentId] = @StudentId">
                        <DeleteParameters>
                            <asp:Parameter Name="StudentId" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="StudentId" Type="Int32" />
                            <asp:Parameter Name="Name" Type="String" />
                            <asp:Parameter Name="Relation" Type="String" />
                        </InsertParameters>
                        <SelectParameters>
                            <asp:ControlParameter ControlID="TextBox1" Name="StudentId" PropertyName="Text" 
                                Type="Int32" />
                        </SelectParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="Name" Type="String" />
                            <asp:Parameter Name="Relation" Type="String" />
                            <asp:Parameter Name="StudentId" Type="Int32" />
                        </UpdateParameters>
                    </asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td class="style10">
                    新增緊急聯絡電話</td>
            </tr>
            <tr>
                <td class="style8">
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TextBox2" ErrorMessage="RegularExpressionValidator" 
                        ValidationExpression="^[0-9]{1,20}$" style="color: #FF0000" 
                        ValidationGroup="phone">僅限數字</asp:RegularExpressionValidator>
                &nbsp;<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="phone"></asp:TextBox>
&nbsp;<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="新增" 
                        ValidationGroup="phone" />
                </td>
            </tr>
            <tr>
                <td class="style10">
                    學生緊急連絡人電話</td>
            </tr>
            <tr>
                <td class="style8">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
                        CellPadding="3" DataKeyNames="serial" DataSourceID="SqlDataSource3" 
                        GridLines="Horizontal" Width="210px">
                        <AlternatingRowStyle BackColor="#F7F7F7" />
                        <Columns>
                            <asp:BoundField DataField="serial" HeaderText="serial" InsertVisible="False" 
                                ReadOnly="True" SortExpression="serial" Visible="False" />
                            <asp:BoundField DataField="StudentId" HeaderText="學生證號" 
                                SortExpression="StudentId" Visible="False" />
                            <asp:BoundField DataField="Phone" HeaderText="緊急聯絡電話" SortExpression="Phone" />
                            <asp:CommandField ButtonType="Button" ShowDeleteButton="True" 
                                ShowEditButton="True" />
                        </Columns>
                        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                        <SortedAscendingCellStyle BackColor="#F4F4FD" />
                        <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
                        <SortedDescendingCellStyle BackColor="#D8D8F0" />
                        <SortedDescendingHeaderStyle BackColor="#3E3277" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                        DeleteCommand="DELETE FROM [EmergencyContactPhone] WHERE [serial] = @serial" 
                        InsertCommand="INSERT INTO [EmergencyContactPhone] ([StudentId], [Phone]) VALUES (@StudentId, @Phone)" 
                        SelectCommand="SELECT * FROM [EmergencyContactPhone] WHERE ([StudentId] = @StudentId)" 
                        UpdateCommand="UPDATE [EmergencyContactPhone] SET [StudentId] = @StudentId, [Phone] = @Phone WHERE [serial] = @serial">
                        <DeleteParameters>
                            <asp:Parameter Name="serial" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:ControlParameter ControlID="TextBox1" Name="StudentId" PropertyName="Text" 
                                Type="Int32" />
                            <asp:ControlParameter ControlID="TextBox2" Name="Phone" PropertyName="Text" 
                                Type="String" />
                        </InsertParameters>
                        <SelectParameters>
                            <asp:ControlParameter ControlID="TextBox1" Name="StudentId" PropertyName="Text" 
                                Type="Int32" />
                        </SelectParameters>
                        <UpdateParameters>
                            <asp:ControlParameter ControlID="TextBox1" Name="StudentId" PropertyName="Text" 
                                Type="Int32" />
                            <asp:Parameter Name="Phone" Type="String" />
                            <asp:Parameter Name="serial" Type="Int32" />
                        </UpdateParameters>
                    </asp:SqlDataSource>
                </td>
            </tr>
        </table>
        <br />
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>
